<%@ page contentType="text/html;charset=UTF-8" language="java"  import="java.util.*" trimDirectiveWhitespaces="true" %>
<%@include file="/WEB-INF/pages/common/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>平台商品新增</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%@include file="/WEB-INF/pages/common/commonCss.jsp"%>

    <link rel="stylesheet" href="${basePath}/resources/css/select2.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-style.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-media.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/bootstrap-wysihtml5.css" />




</head>
<style>
    .select2-container {
        float:left;
        width: 35%;
    }
    .controls.marb5 img{
        margin-bottom:5px;
    }
    label {
        display: inline-block;
        padding-right: 1rem;
    }
    .text-min{
        width: 56px;
    }
    ul li{

    }
    .btn, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
        box-shadow: none;
        width: 4rem;
    }
</style>
<body>

<!--Header-part-->
<%@include file="/WEB-INF/pages/common/head.jsp"%>


<!--sidebar-menu-->
<%@include file="/WEB-INF/pages/common/left.jsp"%>

<div id="content">
    <div id="content-header">
        <div id="breadcrumb"> <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> 规格修改</a>
        <%--<h1>平台商品新增</h1>--%>
    </div>

    <div class="container-fluid">

        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>
                        <h5 style="padding: 4px;">
                            <%--<a href="#myModal"  class="btn btn-primary" data-toggle="modal"><i class="icon-plus" style="padding-right: 0.2rem"></i>新增</a>--%>
                        </h5>
                        <a style="float: right;margin-top: 0.2rem" onclick="tzAdmin.search()" class="btn btn-success"><i class="icon-search icon-white"></i></a>

                        <label style="float: right;margin-top: 0.2rem">
                            <input type="text" style="width: inherit" id="keywords" aria-controls="DataTables_Table_0" placeholder="输入查询关键字">
                        </label>

                    </div>
                    <div class="widget-content nopadding">
                        <input type="hidden" value="${goodId}" id="goodId">

                        <table class="table table-bordered data-table">
                            <thead>

                            <tr>
                                <th>颜色</th>
                                <th>重量</th>
                                <th>材质 <span class="up"></span> <span class="down"></span></th>
                                <th>主石规格</th>
                                <th>手寸</th>
                                <th>项链长度</th>
                                <th>手链长度</th>
                                <th>价格(元)</th>
                                <th>换款价(元)</th>
                                <th>库存(件)</th>
                            </tr>
                            </thead>
                            <tbody id="tbody" >

                            <c:forEach items="${goodchilds}" var="child">
                                <tr data-opid="${child.id}">
                                    <td><input type="text"  name="color" value="${child.color}"></td>
                                    <td><input type="text" name="weight" value="${child.weight}"> </td>
                                    <td><input type="text" name="material" value="${child.material}"></td>
                                    <td><input type="text" name="mainstorespec" value="${child.mainstorespec}"></td>
                                    <td><input type="text" name="handsize" value="${child.handsize}"> </td>
                                    <td><input type="text" name="necklaceLen" value="${child.necklaceLen}"> </td>
                                    <td><input type="text" name="braceletLen" value="${child.braceletLen}"> </td>
                                    <td><input type="number" name="price" value="${child.price}" onkeyup="good.check(this)"></td>
                                    <td><input type="number" name="exprice" value="${child.exprice}" onkeyup="good.check(this)"></td>
                                    <td><input type="number" name="stocknumber" value="${child.stocknumber}"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
                                </tr>
                            </c:forEach>

                            </tbody>
                            <tfoot>

                            </tfoot>
                        </table>
                        <div class="cpage"></div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>




</div>



<!--Footer-part-->
<%@include file="/WEB-INF/pages/common/footer.jsp"%>

<!--end-Footer-part-->

<%@include file="/WEB-INF/pages/common/commonJS.jsp"%>
<script src="${basePath}/resources/js/bootstrap.min.js"></script>
<script src="${basePath}/resources/js/kindeditor-4.1.10/kindeditor.js"></script>
<script src="${basePath}/resources/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script src="${basePath}/resources/js/kindeditor-4.1.10/plugins/code/prettify.js"></script>
<script type="text/javascript" src="${basePath}/resources/js/upload/upload.js"></script>


<script>

    KindEditor.ready(function(K) {
        K.create('#editor_id', {
            uploadJson : basePath+'/kindEditor/fileUpload',
            fileManagerJson : basePath+'/kindEditor/fileManager',
            allowFileManager : true ,
            afterCreate : function() {
                var self = this;
                K.ctrl(document, 13, function() {
                    self.sync();
                    document.forms['example'].submit();
                });
                K.ctrl(self.edit.doc, 13, function() {
                    self.sync();
                    document.forms['example'].submit();
                });
            },
            //下面这行代码就是关键的所在，当失去焦点时执行 this.sync();
            afterBlur: function(){this.sync();}
        });
        prettyPrint();
    })


    var good = {
        controlShow:function () {
            $("#tbody").children("tr:first-child").find("input[type='text']").each(function (index,item) {
                   //console.log(index+'===='+item+'=='+$(item).val());
                   if(!$(item).val()) {
                       $('table tr').find('td:eq('+index+')').hide();
                       $('table tr').find('th:eq('+index+')').hide();
                   }
            });
        },
        check:function (obj) {
            var reg = /^\d+\.?(\d{1,2})?$/;
            var val = $(obj).val();
            if(!reg.test(val)){
                $(obj).val("");
                $(obj).focus();
            }
        },
        confirm:function () {
            $("input").on('change',function () {
                var val = $(this).val();
                if(!val){
                    loading("不能为空",3);
                    $(this).focus();
                    return;
                }
                var id=$(this).parent().parent().data("opid");
                var goodId = $('#goodId').val();
                var name = $(this).attr('name');
                var data = {id:id,goodId:goodId};
                data[name] = val;
                console.log(JSON.stringify(data));
                $.ajax({
                    url:adminPath+"/shop/good/updateSpec",
                    type:"post",
                    data:data,
                    success:function (data) {
                        if(data==1){
                            loading("修改规格成功",3);
                        }
                    }

                });
            });
        }
    };





    $(function () {
        good.controlShow();
        good.confirm();
    })
</script>

</body>
</html>
